const fs = require('fs')
const xlsx = require('node-xlsx')
const path = require('path')

const sheets = xlsx.parse(path.join(__dirname, '../zrdq.xlsx'))
sheets.forEach(sheet => {
  // sheet name
  if (sheet.name == '系统翻译') {
    // 获取整个excel中的数据
    const data = sheet['data']

    // 将需要的列数据组装成数组
    const keys = []
    const en = []
    data.forEach(d => {
      keys.push(d[1])
      en.push(d[3])
    })
    // 去掉无用数据
    keys.shift()
    en.shift()
    console.log('=== keys', keys)
    console.log('=== en', en)
    const json = {}
    keys.forEach((k, i) => {
      json[k] = en[i]
    })
    fs.writeFile(path.join(__dirname, '../src/locales/en.json'), JSON.stringify(json, null, 2), (err) => {
      if (err) throw err
      console.log('The file has been saved!')
    })
  }
})
